package chixing.day05;

public class Library {
        private Book[] allBooks;
        private int size = 0; // 图书馆中 已有书的个数

    public Library(){
        allBooks = new Book[100];
        Book book1 = new Book(1,"Java编程思想","Bruce Eckel",true);
        Book book2 = new Book(2,"算法导论","Cormen",true);
        Book book3 = new Book(3,"数据库系统概念","Silbersch",true);
        Book book4 = new Book(4,"设计模式","Gamma",true);
        Book book5 = new Book(5,"代码大全","McConnell",true);
        this.addBook(book1);
        this.addBook(book2);
        this.addBook(book3);
        this.addBook(book4);
        this.addBook(book5);
    }
    public void addBook(Book book){
        allBooks[size++] = book;
    }
    public Book getBookByISBN(int isbn) {
        for (int i = 0; i < size; i++) {
            if (allBooks[i].getBookIsbn()== isbn) {
                return allBooks[i];
            }
        }
        return null;
    }
    public void displayAvailableBooks() {
        for (int i = 0; i < size; i++) {
            if (allBooks[i].isAvailable()) {
                System.out.println(allBooks[i]);
            }
        }
    }
}
